﻿@using CoralNode.Core.Entity.Enums
@using CoralNode.MvcClient.Helper
@using Coralcode.Base.Utils

@Html.IncludePage("CoralAdmin/prototype", "_Left", new { current = "block" })
<div id="pbody">
    <div class="extra">
        <div class="pbody_top">
            <span class="ico ico_setting_setting"></span><span class="t t_c">内容设计&nbsp;&nbsp;/&nbsp;&nbsp;内容块设计</span>
        </div>
        <div id="main">
            <div class="">
                <div class="tablelist_style1" data-js="tabellist_style1">
                    <div class="funsearch p_1 pl_2 pr_2 extra_normal">
                        <div class="f_l">
                            <div class="select_owner w_12-5 " data-meta="{value:'@ViewBag.Query.GroupId', btn:'<span class=\'ico ico_slide_down\'></span>' , clickbtn:'<span class=\'ico ico_slide_up\'></span>'}">
                                <ul>
                                    @foreach (var item in @ViewBag.GroupList) {
                                        if (@item.Id == @ViewBag.Query.GroupId) {
                                        <li data-value="@item.Id"><a class="current" href="/m/prototype/listblock?GroupId=@item.Id">@item.Title</a>
                                        </li>
                                        } else {
                                        <li data-value="@item.Id"><a  href="/m/prototype/listblock?GroupId=@item.Id">@item.Title</a>
                                        </li>
                                        }
                                    }
                                </ul>
                            </div>

                            <a href="#" class="btn_4 mt_0-5 f_l ml_2" data-title="字段组管理" data-dialog=""
                                id="groupmanager">分组管理</a>
                            <div id="groupcontent">
                                <ul class="list_tag d_GroupTabDialog " data-savehref="/m/prototype/SaveBlockGroup"
                                    data-delhref="/m/prototype/DelBlockGroup/" id="addTabDialog">
                                    @foreach (var item in ViewBag.GroupList) {
                                        <li><span>@item.Title</span><input type="text" data-groupid="@item.Id" value="@item.Title"><i
                                            class="del"></i>
                                        </li>
                                    }
                                    <li class="add"><a class="btn_4">添 加</a></li>
                                </ul>
                            </div>
                        </div>
                        <a class="btn_5 f_r ml_3" href="/m/prototype/createBlock?groupId=@ViewBag.Query.GroupId">
                            &nbsp;添加块</a>
                        <div class="f_r">
                            <form method="POST" action="/m/prototype/listBlock">
                                <label class="search f_l">
                                    <input type="hidden" name="Ttile" class="text w_18" msg="请输入关键字" />
                                    @Html.AntiForgeryToken()
                                    @Html.Hidden("GroupId", (long)ViewBag.Query.GroupId)
                                    <input type="submit" value="" class="submit" />
                                </label>
                            </form>
                        </div>
                    </div>
                    <table cellpadding="0" cellspacing="0">
                        <tr class="exclude">
                            <th width="60">选择</th>
                            <th align="left" width="50">ID</th>
                            <th align="left">名称</th>
                            <th>类型</th>
                            <th align="center" width="140">操作</th>
                        </tr>
                        @foreach (var item in Model.Items) {
                            <tr>
                                <td>
                                    <label class="checkbox_own">
                                        <input type="checkbox" value="@item.Id"/></label></td>
                                <td class="td_left">@item.Id</td>
                                <td class="td_left"><a href="/m/prototype/editBlock/@item.Id">@item.Title</a></td>
                                <td>@EnumUtil.GetEnumDescription(SiteEnums.BlcokType, item.Type)</td>
                                <td>
                                    <div class="fun">
                                        <a href="/m/prototype/editBlock/@item.Id">编辑</a><a href="/m/prototype/DeleteBlock/@item.Id" class="js_delete">删除</a>
                                    </div>
                                </td>
                            </tr>
                        }
                    </table>
                    <div class="global_fun ">
                        <label class="checkbox_own gloabal_select">
                            <input type="checkbox" /></label>
                        <input type="button" class="btn_4 btn invert" value="反选" /><input type="button" class="btn_4 btn reset"
                            value="重置" />
                        <a href="#" class="js_delete">删除</a>
                    </div>
                </div>

            </div>
        </div>
        <div id="pager">
            <div class="info_pg">共@(Model.TotalItems)条</div>
            <div class="list_pg">
                <a href="/m/prototype/listBlock?@ViewBag.queryString&p=1" class="first">首页</a>
                @if (@Model.HasPreviousPage && @Model.TotalItems > 0) {
                    <a href="/m/prototype/listBlock?@ViewBag.queryString&p=@Model.PreviousPageIndex" class="prev">
                        上一页</a>
                } else {
                    <a class="prev none">上一页</a>
                }
                @foreach (var i in @Model.PageArray) {
                    if (@i == @Model.CurrentPageIndex) {
                    <a class="current">@i</a>
                    } else if (@i == 0) {
                    <a class="more">…</a>
                    } else {
                    <a href="/m/prototype/listBlock?@ViewBag.queryString&p=@i" href="#">@i</a>
                    }
                }
                @if (@Model.HasNextPage && @Model.TotalItems > 0) {
                    <a class="next" href="/m/prototype/listBlock?@ViewBag.queryString&p=@Model.NextPageIndex">
                        下一页</a>
                } else {
                    <a class="next none">下一页</a>
                }
                <a class="last" href="/m/prototype/listBlock?@ViewBag.queryString&p=@Model.TotalPages">
                    尾页</a>
                <!-- <span class="msg">跳转</span>
                <input class="text" type="text" value="">
                <span class="msg">页</span>-->
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        $('.nav_left_style2').find('li').eq(4).addClass('current');

        $('#groupmanager').live('click', function () {
            var $this = $(this);
            var refId = $("#prototypeId").val();
            var html = $("#groupcontent").html();

            $.dialog({
                content: html,
                width: 400,
                title: "内容块分组管理",
                lock: true,
                cancel: true,
                ok: function () {
                    location.reload();
                }
            });
        });
        $('#addTabDialog > li:not(".add") > span').live('click', function () {
            $(this).hide().next().show().focus().next().css('visibility', 'hidden');
        });
        $('#addTabDialog > li:not(".add") > :text').live('focusout', function () {
            var $val = $(this).hide().val();
            $(this).next().css('visibility', 'visible');
            $(this).prev().text($val).show();
        });
        $('#addTabDialog > li:not(".add") > i').live('click', function () {
            var $this = $(this);
            var groupId = $this.prev().attr("data-groupid");
            var action = $('#addTabDialog').attr("data-delhref");
            $.post(action + groupId, function (data) {
                if (data.Type == 5) {
                    $('#groupcontent').find('li').eq($this.parent().index()).remove();
                    $this.parent().fadeOut(function () {
                        $this.parent().remove();
                    });
                } else {
                    $.alert(data.Msg, "error");
                }
            });
        });
        $('#addTabDialog >li.add').live('click', function () {
            $(this).before('<li><span>未命名</span><input class="post_fieldGorup" type="text" value="未命名" /><i class="del"></i></li>');
            $(this).prev().find('span').trigger('click');
        });
        $('#addTabDialog >li>input').live('blur', function () {
            var $this = $(this);
            var refId = $("#refId").val();
            var action = $('#addTabDialog').attr("data-savehref");
            var gId = $this.attr("data-groupid") != undefined ? $this.attr("data-groupid") : 0;
            $.post(action, { Id: gId, title: $this.val() }, function (data) {
                if (data != null && data.Id != undefined) {
                    $this.attr("data-groupid", data.Id);
                    $('#groupcontent').find('li.add').before('<li><span>' + data.Title + '</span><input type="text" data-groupid="' + data.Id + '" value="' + data.Title + '"><i class="del"></i></li>');
                }
                else {
                    $.alert(data.Msg);
                }

            });
        });

    });
</script>
